/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaAgregarUsuarioProyecto.java
 *
 * Created on 02-jun-2012, 1:07:23
 */
package edu.eam.gruposenior.gestorLEcciones.vista;

import java.util.List;

import javax.swing.JOptionPane;

import edu.eam.gruposenior.gestorLEcciones.controladores.ProyectoController;
import edu.eam.gruposenior.gestorLEcciones.controladores.UsuarioController;
import edu.eam.gruposenior.gestorLEcciones.entidades.Proyecto;
import edu.eam.gruposenior.gestorLEcciones.entidades.Usuario;

/**
 * 
 * @author Claudia
 */
public class VentanaAgregarUsuarioProyecto extends javax.swing.JFrame {

	/** Creates new form VentanaAgregarUsuarioProyecto */
	public VentanaAgregarUsuarioProyecto() {
		initComponents();

		List<Usuario> listaUsu = new UsuarioController().usuarios();

		for (Usuario us : listaUsu) {
			cbUsuario.addItem(us);
		}

		List<Proyecto> listaPro = new ProyectoController().proyectos();

		for (Proyecto pro : listaPro) {
			cbProyecto.addItem(pro);
		}
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		cbUsuario = new javax.swing.JComboBox();
		cbProyecto = new javax.swing.JComboBox();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		bRegistrar = new javax.swing.JButton();
		bCancelar = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jLabel1.setText("Usuario");

		jLabel2.setText("Proyecto");

		bRegistrar
				.setIcon(new javax.swing.ImageIcon(
						getClass()
								.getResource(
										"/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Add.png"))); // NOI18N
		bRegistrar.setText("Registrar");
		bRegistrar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bRegistrarActionPerformed(evt);
			}
		});

		bCancelar
				.setIcon(new javax.swing.ImageIcon(
						getClass()
								.getResource(
										"/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Close.png"))); // NOI18N
		bCancelar.setText("Cancelar");
		bCancelar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bCancelarActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(21, 21, 21)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING,
												false)
												.addComponent(
														jLabel1,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														jLabel2,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(43, 43,
																		43)
																.addComponent(
																		bCancelar)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(
																		bRegistrar))
												.addGroup(
														layout.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																false)
																.addComponent(
																		cbUsuario,
																		0,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		cbProyecto,
																		0,
																		281,
																		Short.MAX_VALUE)))
								.addContainerGap(37, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(62, 62, 62)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														cbUsuario,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel1))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														cbProyecto,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel2))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(bCancelar)
												.addComponent(bRegistrar))
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void bRegistrarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bRegistrarActionPerformed
		new ProyectoController().crearProyectoUsuario(
				(Proyecto) cbProyecto.getSelectedItem(),
				(Usuario) cbUsuario.getSelectedItem());
		JOptionPane.showMessageDialog(null, "Creado con exito");
	}// GEN-LAST:event_bRegistrarActionPerformed

	private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bCancelarActionPerformed
		this.dispose();
	}// GEN-LAST:event_bCancelarActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new VentanaAgregarUsuarioProyecto().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton bCancelar;
	private javax.swing.JButton bRegistrar;
	private javax.swing.JComboBox cbProyecto;
	private javax.swing.JComboBox cbUsuario;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	// End of variables declaration//GEN-END:variables
}
